package mutsumimod.patches;

import basemod.CustomCharacterSelectScreen;
import basemod.ReflectionHacks;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePostfixPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePrefixPatch;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.screens.charSelect.CharacterSelectScreen;
import mutsumimod.character.Mutsumi;
import mutsumimod.ui.MutsumiCharaterSelectScreen;

public class MutsumiSelectCharacterPatch {
    public static boolean isMutsumiSelected() {
        if (CardCrawlGame.chosenCharacter == null) {
            return false;
        }
        return (CardCrawlGame.chosenCharacter.equals(Mutsumi.Meta.MUTSUMI) && ((Boolean) ReflectionHacks.
                getPrivate(CardCrawlGame.mainMenuScreen.charSelectScreen, CharacterSelectScreen.class, "anySelected")).booleanValue());
    }

    @SpirePatch(clz = CustomCharacterSelectScreen.class, method = "render")
    public static class RenderButtonPatch {
        @SpirePostfixPatch
        public static void Postfix(CustomCharacterSelectScreen _inst, SpriteBatch sb) {
            if (MutsumiSelectCharacterPatch.isMutsumiSelected()) {
                MutsumiCharaterSelectScreen.Inst.render(sb);
            }
        }
    }

    @SpirePatch(clz = CharacterSelectScreen.class, method = "update")
    public static class UpdateButtonPatch {
        @SpirePrefixPatch
        public static void Prefix(CharacterSelectScreen _inst) {
            if (MutsumiSelectCharacterPatch.isMutsumiSelected())
                MutsumiCharaterSelectScreen.Inst.update();
        }
    }
}
